<?php
//verifyEmail hack!

require_once("Utils.php");

define('MAIL_VALID',1);
define('MAIL_INVALID',0);
define('ERROR_VALIDATING',-1);

function verifyMailMethod1($mail)
{
	$resstr = Utils::httpPost("www.email-unlimited.com","/tools/verify-email.aspx","Email=".$mail);
	if($resstr === FALSE)
		return ERROR_VALIDATING;
	$resultpos = strpos($resstr,"<b>Result</b>");
	while($resultpos !== FALSE)
	{
		$part = substr($resstr,$resultpos,45);
		if(strpos($part,"OK") !== FALSE)
		{
			return MAIL_VALID;
		}
		$resultpos = strpos($resstr,"<b>Result</b>",$resultpos+10);
	}
	return MAIL_INVALID;
}

function verifyMailMethod2($mail)
{
	$resstr = Utils::httpPost("www.verifyemailaddress.org","/","email=".$mail);
	if($resstr === FALSE)
		return ERROR_VALIDATING;
	$resultpos = strpos($resstr,'<div class="success valid">');
	$l = strlen($mail)+50;
	while($resultpos !== FALSE)
	{
		$part = substr($resstr,$resultpos,$l);
		if(strpos($part,$mail." is valid") !== FALSE)
		{
			return MAIL_VALID;
		}
		$resultpos = strpos($resstr,'<div class="success valid">',$resultpos+10);
	}
	return MAIL_INVALID;
}

function validateMail($mail)
{
	$ret = verifyMailMethod2($mail);
	if($ret == ERROR_VALIDATING)
		$ret = verifyMailMethod1($mail);
	return $ret;
}

?>